// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
       rotateValue: {
        default: 30,
        type: cc.Integer,
        tooltip: '星星的旋转角度'
       },
       rotateSpeed: {
        type: cc.Integer,
        default: 2,
        tooltip: '星星的旋转速度'
       }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },
    // 根据rotateValue旋转角度和旋转速度，让该节点旋转起来
    update (dt) {
        this.node.angle += this.rotateValue * this.rotateSpeed * dt;
        // 当前节点向场景中心点移动
        this.node.x -= this.rotateValue * this.rotateSpeed * dt;
        if (this.node.x < -cc.winSize.width / 2) {
            this.node.x = cc.winSize.width / 2;
        }
        if (this.node.x > cc.winSize.width / 2) {
            this.node.x = -cc.winSize.width / 2;
        }
        if (this.node.y < -cc.winSize.height / 2) {
            this.node.y = cc.winSize.height / 2;
        }
        if (this.node.y > cc.winSize.height / 2) {
            this.node.y = -cc.winSize.height / 2;
        }
        this.node.y += this.rotateValue * this.rotateSpeed * dt;
        if (this.node.y < -cc.winSize.height / 2) {
            this.node.y = cc.winSize.height / 2;
        }
        this.node.y += this.rotateValue * this.rotateSpeed * dt;
        if (this.node.y > cc.winSize.height / 2) {
            this.node.y = -cc.winSize.height / 2;
        }
        this.node.y += this.rotateValue * this.rotateSpeed * dt;
        
    },
});
